﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Pout_Porri.Objects.Interface;
using Pout_Porri.Levels;

namespace Pout_Porri.Objects
{
    //Classe base para elementos do jogo
    abstract class GameEntity
    {
        /// <summary>
        /// A position
        /// </summary>
        public Vector2 position;
        
        /// <summary>
        /// An image
        /// </summary>
        private Texture2D image;

        /// <summary>
        /// if the sprite is visible
        /// </summary>
        private bool visible = true;

        /// <summary>
        /// uma margem para corrigir as linhas e colunas (ele soma nos dois) no spritesheet
        /// </summary>
        protected Vector2 offset;
        public Vector2 Offset
        {
            get { return offset; }
            set { offset = value; }
        }        

        public Rectangle CollisionRect
        {
            get
            {
                return new Rectangle((int)(position.X + offset.X) , (int)(position.Y + offset.Y), image.Width, image.Height);
            }
        }

        private Level myLevel;
        public Level MyLevel
        {
            get { return myLevel; }
            set { myLevel = value; }
        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="img">An image</param>
        public GameEntity(Texture2D img)
        {
            this.image = img;
        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="img">The image of the sprite</param>
        /// <param name="position">The position of the sprite</param>
        public GameEntity(Texture2D img, Vector2 position)
        {
            this.image = img;
            this.position = position;
        }

        /// <summary>
        /// Gets the image of this sprite
        /// </summary>
        /// <returns>The image</returns>
        public Texture2D getImage()
        {
            return this.image;
        }

        /// <summary>
        /// if this entity is visible;
        /// </summary>
        /// <returns>True if the entity is visible</returns>
        public bool isVisible()
        {
            return visible;
        }

        /// <summary>
        /// Sets the visibility of this object
        /// </summary>
        /// <param name="b"></param>
        public void setVisible(bool b)
        {
            this.visible = b;
        }

        /// <summary>
        /// Para não executar a função keepinworld
        /// pois ela da um bug no posicionamento 
        /// de objetos na tela, visto que as dimensões
        /// utilizadas inicialmente, podem não ser as mais 
        /// adequadas para cada jogo.
        /// </summary>
        public bool useKeepInWorld = true;


        /// <summary>
        /// Update this entity
        /// </summary>
        /// <param name="gameTime">The time of the game</param>
        public abstract void update(GameTime gameTime);

        /// <summary>
        /// draws this entity
        /// </summary>
        /// <param name="spriteBatch">A spriteBatch</param>
        public virtual void draw(SpriteBatch spriteBatch)
        {
            //nem chego aqui...
            //spriteBatch.Draw(this.image, this.position, Color.White);
        }

    }
}
